1 Imports System.Data.SqlClient
2 Imports Excel = Microsoft.Office.Interop.Excel
3 Imports System.IO
4
5 Public Class frmCustomerRecord2
6
7 Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
8 Me.Close()
9 End Sub
10 Public Sub Getdata()
11 Try
12 con = New SqlConnection(cs)
13 con.Open()
14 cmd = New SqlCommand("SELECT RTRIM(ID),RTRIM(CustomerID),RTRIM([Name]),RTRIM(Gender), RTRIM(Address),RTRIM(City),RTRIM(State),RTRIM(ZipCode), RTRIM(ContactNo), RTRIM(EmailID),RTRIM(Remarks),Photo from Customer where CustomerType='Regular' order by name", con)
15 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
16 dgw.Rows.Clear()
17 While (rdr.Read() = True)
18 dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11))
19 End While
20 con.Close()
21 Catch ex As Exception
22 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
23 End Try
24 End Sub
25 Private Sub frmLogs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
26 Getdata()
27 End Sub
28
29 Private Sub btnClose_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
30 Me.Close()
31 End Sub
32
33 Private Sub dgw_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
34 Try
35 If dgw.Rows.Count > 0 Then
36 Dim dr As DataGridViewRow = dgw.SelectedRows(0)
37
38 If lblSet.Text = "Billing" Then
39 frmBilling.Show()
40 Me.Hide()
41 frmBilling.txtCID.Text = dr.Cells(0).Value.ToString()
42 frmBilling.txtCustomerID.Text = dr.Cells(1).Value.ToString()
43 frmBilling.txtCustomerName.Text = dr.Cells(2).Value.ToString()
44 frmBilling.txtContactNo.Text = dr.Cells(8).Value.ToString()
45 frmBilling.txtCustomerName.ReadOnly = True
46 frmBilling.txtContactNo.ReadOnly = True
47 lblSet.Text = ""
48 End If
49 If lblSet.Text = "Quotation" Then
50 frmQuotation.Show()
51 Me.Hide()
52 frmQuotation.txtCID.Text = dr.Cells(0).Value.ToString()
53 frmQuotation.txtCustomerID.Text = dr.Cells(1).Value.ToString()
54 frmQuotation.txtCustomerName.Text = dr.Cells(2).Value.ToString()
55 frmQuotation.txtContactNo.Text = dr.Cells(8).Value.ToString()
56 frmQuotation.txtCustomerName.ReadOnly = True
57 frmQuotation.txtContactNo.ReadOnly = True
58 lblSet.Text = ""
59 End If
60 If lblSet.Text = "Services" Then
61 frmServices.Show()
62 Me.Hide()
63 frmServices.txtCID.Text = dr.Cells(0).Value.ToString()
64 frmServices.txtCustomerID.Text = dr.Cells(1).Value.ToString()
65 frmServices.txtCustomerName.Text = dr.Cells(2).Value.ToString()
66 frmServices.txtContactNo.Text = dr.Cells(8).Value.ToString()
67 lblSet.Text = ""
68 End If
69 End If
70 Catch ex As Exception
71 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
72 End Try
73
74 End Sub
75
76 Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
77 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
78 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
79 If dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
80 dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
81 End If
82 Dim b As Brush = SystemBrushes.ControlText
83 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
84
85 End Sub
86
87 Private Sub txtCustomerName_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCustomerName.TextChanged
88 Try
89 con = New SqlConnection(cs)
90 con.Open()
91 cmd = New SqlCommand("SELECT RTRIM(ID),RTRIM(CustomerID),RTRIM([Name]),RTRIM(Gender), RTRIM(Address),RTRIM(City),RTRIM(State),RTRIM(ZipCode), RTRIM(ContactNo), RTRIM(EmailID),RTRIM(Remarks),Photo from Customer where CustomerType='Regular' and name like '%" & txtCustomerName.Text & "%' order by name", con)
92 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
93 dgw.Rows.Clear()
94 While (rdr.Read() = True)
95 dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11))
96 End While
97 con.Close()
98 Catch ex As Exception
99 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
100 End Try
101 End Sub
102
103 Private Sub txtCity_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCity.TextChanged
104 Try
105 con = New SqlConnection(cs)
106 con.Open()
107 cmd = New SqlCommand("SELECT RTRIM(ID),RTRIM(CustomerID),RTRIM([Name]),RTRIM(Gender), RTRIM(Address),RTRIM(City),RTRIM(State),RTRIM(ZipCode), RTRIM(ContactNo), RTRIM(EmailID),RTRIM(Remarks),Photo from Customer where CustomerType='Regular' and City like '%" & txtCity.Text & "%' order by city", con)
108 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
109 dgw.Rows.Clear()
110 While (rdr.Read() = True)
111 dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11))
112 End While
113 con.Close()
114 Catch ex As Exception
115 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
116 End Try
117 End Sub
118 Sub Reset()
119 txtCustomerName.Text = ""
120 txtContactNo.Text = ""
121 txtCity.Text = ""
122 Getdata()
123 End Sub
124
125 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
126 Reset()
127 End Sub
128
129 Private Sub txtContactNo_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtContactNo.TextChanged
130 Try
131 con = New SqlConnection(cs)
132 con.Open()
133 cmd = New SqlCommand("SELECT RTRIM(ID),RTRIM(CustomerID),RTRIM([Name]),RTRIM(Gender), RTRIM(Address),RTRIM(City),RTRIM(State),RTRIM(ZipCode), RTRIM(ContactNo), RTRIM(EmailID),RTRIM(Remarks),Photo from Customer where CustomerType='Regular' and ContactNo like '%" & txtContactNo.Text & "%' order by city", con)
134 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
135 dgw.Rows.Clear()
136 While (rdr.Read() = True)
137 dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11))
138 End While
139 con.Close()
140 Catch ex As Exception
141 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
142 End Try
143 End Sub
144
145 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
146 frmCustomer.lblUser.Text = lblUser.Text
147 frmCustomer.Reset()
148 frmCustomer.Reset()
149 frmCustomer.ShowDialog()
150 End Sub
151
152 End Class